<template>
  <div>
    <!-- <p>ID: {{ form.id }}</p>
    <p>Name: {{ form.name }}</p>
    <p>User Name: {{ form.content }}</p> -->
    <h1>{{ form.title }}</h1>
    <el-form
      :model="form"
      status-icon
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="用户名" prop="userName">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="留言信息" prop="content">
        <el-input v-model="form.content"></el-input>
      </el-form-item>
      <el-form-item label="用户角色">
        <el-select :placeholder="control" v-model="control" disabled>
          <el-option label="请选择" value="0"></el-option>
          <el-option label="管理员" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="send()">{{ form.button }}</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
export default {
  data() {
    return {
      form: {
        id: "",
        name: "",
        userName: "",
        passWord: "",
        role: "",
        content: "",
        title: "添加内容",
        control: 1,
        button: "添加",
      },
    };
  },
  created() {
    this.form.id = this.$route.query.id;
    this.form.name = this.$route.query.name;
    this.form.content = this.$route.query.content;
    if (this.$route.query.id != undefined) {
      this.form.title = "修改内容";
      this.form.control = 1;
      this.form.button = "修改";
    } else {
      this.form.title = "添加内容";
      this.form.control = 1;
      this.form.button = "添加";
    }
  },
  methods: {
    send() {
      console.log(this.$route.query.id, "this.$route.query.id");
      if (this.$route.query.id != undefined) {
        this.$message("修改成功");
        this.$axios
          .put("http://wish.byesame.com/wish", {
            id: this.form.id,
            name: this.form.name,
            content: this.form.content,
          })
          .then((r) => {
            console.log(r, "修改数据");
          });
        this.$router.push("/home/lookview");
      } else {
        console.log("添加");
        this.$message("添加成功");
        this.$axios
          .post("http://wish.byesame.com/wish", {
            name: this.form.name,
            content: this.form.content,
            role: 2,
          })
          .then((r) => {
            console.log(r, "添加内容");
          });
        this.$router.push("/home/lookview");
      }
    },
  },
};
</script>

<style>
</style>